﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace postSale.forms
{
    public partial class message : application.baseForm  
    {
        private processWorkEdit _myProcessEdit = null;
        private processWorkEdit myProcessEdit
        {
            get
            {
                if (_myProcessEdit==null) _myProcessEdit = new processWorkEdit();
                return _myProcessEdit;
            }
        }

        private processAssignEdit _myProcessAssignEdit = null;
        private processAssignEdit myProcessAssignEdit
        {
            get
            {
                if (_myProcessAssignEdit == null) _myProcessAssignEdit = new processAssignEdit();
                return _myProcessAssignEdit;
            }
        }
        public int myTaskCount
        {
            get { return myPostSalesDS.tasks.Count; }
        }

        public message()
        {
            InitializeComponent();
            this.myStatusStrip.Visible = false;
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            //Get the screen size
            Rectangle WorkingArea = Screen.GetWorkingArea(new Point(0, 0));
            //Position the current form
            this.Location = new Point((WorkingArea.Width - this.Width), (WorkingArea.Height - this.Height));
        }

        public int LoadInCompletedTasks()
        {
            myPostSalesDS.tasks.Clear();
            byte type = (byte)myTypes.taskType.Auto;
            byte status = (byte)common.CommonStatus.New + (byte)common.CommonStatus.Processing;
            taskTA.FillByTypeStatMaskRecipient(myPostSalesDS.tasks,
                        type.ToString(), status.ToString(),
                        common.Consts.SQL_CMD_ALL_MARKER + CommonTypes.Settings.sysLoginInfo.UserId.ToString() + postSale.consts.constListSepator.ToString() + common.Consts.SQL_CMD_ALL_MARKER);

            return myPostSalesDS.tasks.Count;
        }

        private void closeImg_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

        private void minimizeImg_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        private void listGrid_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                this.ShowMessage("");
                if (taskSource.Current == null) return;
                data.postSaleDS.tasksRow taskRow = (data.postSaleDS.tasksRow)((DataRowView)taskSource.Current).Row;
                if (taskRow.status == (byte)common.CommonStatus.New) myProcessAssignEdit.ShowProcess(taskRow.taskId, true);
                else myProcessEdit.ShowProcess(taskRow.taskId, true);
            }
            catch (Exception er)
            {
                this.ShowError(er);
            }
        }
    }
}
